﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DP.Common;
using CRM.BLL;
using CRM.Web.EventManagement.ucControl;
using DP.Web.UI;

namespace CRM.Web.EventManagement
{
    public partial class AdvancedExtract : Common.PageBase
    {
        public string TaskId
        {
            set
            {
                ViewState["TaskID"] = value;
            }
            get
            {
                return ViewState["TaskID"] == null ? "" : ViewState["TaskID"].ToString();
            }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            PageHelper.SetPrePageUrl(this.Page);
            if (PageHelper.GetQueryString(this.Page, "PageTarget") != "Opener")
            {
                PageHelper.SetGoBackUrl(this.Page, btnCancel, StaticConstant.NotBackUrl);
                btnCancel.Attributes["onclick"] = UserLoginInfo.FilterBackUrl(btnCancel.Attributes["onclick"]);
            }
            else
            {
                PageHelper.SetClose(this.Page, btnCancel);
                btnCancel.Value = "关 闭";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                TaskId = PageHelper.GetQueryString(this.Page, "TASK_ID");
                ddlListSourceBinding();
                pageInit();
            }

        }


        private void ddlListSourceBinding()
        {
            EnumHelper.FillListControl(ddlListSource, typeof(AdvancedExtractSource));
            ddlListSource.Items.Insert(0, new ListItem("", ""));
        }



        private void pageInit()
        {
            ucPotentialCustomer.Visible = false;
            iucControl control = GetSelectControl(ddlListSource);
            if (control != null)
            {
                control.Show(_userLoginInfo, TaskId);
            }
        }

        protected void ddlListSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            pageInit();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            iucControl control = GetSelectControl(ddlListSource);
            if (control != null)
            {
                control.Search();
            }
        }

        protected void btnExtract_Click(object sender, EventArgs e)
        {
            iucControl control = GetSelectControl(ddlListSource);
            if (control != null)
            {
                control.Extract();
            }
        }


        private iucControl GetSelectControl(DropDownList ddl)
        {
            iucControl obj = null;
            if (String.IsNullOrEmpty(ddl.SelectedValue.Trim()))
            {
                return obj;
            }
            switch ((AdvancedExtractSource)Enum.Parse(typeof(AdvancedExtractSource), ddl.SelectedValue.Trim()))
            {
                case AdvancedExtractSource.潜在客户:
                    {
                        obj = ucPotentialCustomer;
                    }
                    break;
                default:
                    {

                    }
                    break;
            }
            return obj;
        }



    }
}
